<?php
namespace yan\currency\factory;
class FreeCurrencyApi extends \yan\currency\AbstractFactory{
	public function run($service){
		$param['apikey'] =  getenv('FREECURRENCYAPI');
		$param['base_currency'] = 'USD';
		// $param['currencies'] = 'EUR,USD,CAD';
		$url = 'https://api.freecurrencyapi.com/v1/latest?'. http_build_query($param);
		$response = $service->curl->build($url)->run();
		$data = json_decode($response, true);

		$currencies = [];
		$currencies['USD'] = '1.0000';
		if(!empty($data['data'])){
			$currencies = array_merge($currencies, $data['data']);
		}
		return $currencies;
	}
}